package log

type Level int

const (
	LvMax Level = 4

	Test  Level = 4
	Trace Level = 3
	I     Level = 2
	W     Level = 1
	E     Level = 0
)

type Options struct {
	showOnConsole bool
	logDir        string
	logLevel      Level
	logBatchSize  uint64
}

type Option func(op *Options)

func ShowOnConsole(v bool) func(op *Options) {
	return func(op *Options) {
		op.showOnConsole = v
	}
}
func LogDir(v string) func(op *Options) {
	return func(op *Options) {
		op.logDir = v
	}
}
func LogLevel(v Level) func(op *Options) {
	return func(op *Options) {
		op.logLevel = v
	}
}
func LogBatchSize(byteSize uint64) func(op *Options) {
	return func(op *Options) {
		op.logBatchSize = byteSize
	}
}

type ILog interface {
	Init(options ...Option)
	Info(module string, level Level, format string, args ...interface{})
	Warn(module string, format string, args ...interface{})
	Error(module string, format string, args ...interface{})
}

var logger = &FileLog{}

func Init(options ...Option) {
	logger.Init(options...)
}

// Record log just goes to storage, no console output, no log level checking
func Record(module string, format string, args ...interface{}) {
	logger.Record(module, format, args...)
}

func Info(module string, level Level, format string, args ...interface{}) {
	logger.Info(module, level, format, args...)
}

func Warn(module string, format string, args ...interface{}) {
	logger.Warn(module, format, args...)
}

func Error(module string, format string, args ...interface{}) {
	logger.Error(module, format, args...)
}
func Panic(module string, format string, args ...interface{}) {
	logger.Panic(module, format, args...)
}

func Flush() {
	logger.Flush()
}
